//package com.lab.book.web.config;
//
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.builders.WebSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//
//@EnableWebSecurity
//@Configuration
//@EnableGlobalMethodSecurity(prePostEnabled = true)
//public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
//    @Override
//    protected void configure(HttpSecurity http) throws Exception {
//        //http.authorizeRequests().anyRequest().permitAll().and().logout().permitAll();
//        http.authorizeRequests()//配置安全策略
//                .antMatchers("/", "/abc","/springLogin").permitAll()//定义/请求不需要验证
//                .anyRequest().authenticated()//其余的所有请求都需要验证
//                .and()
//                .logout()
//                .permitAll()//定义logout不需要验证
//                .and()
//                .formLogin()
//                    .loginPage("/springLogin")
//                    .loginProcessingUrl("/login")
//                    .usernameParameter("uname")
//                    .passwordParameter("pwd")
//                    .defaultSuccessUrl("/")
//        ;//使用form表单登录
//    }
//
//    @Override
//    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//        //inMemoryAuthentication 从内存中获取
//        auth.inMemoryAuthentication()
//                .passwordEncoder(passwordEncoder())
//                .withUser("jazz").password(passwordEncoder().encode("Aa123456")).roles("USER");
//
//        auth.inMemoryAuthentication()
//                .withUser("admin").password(passwordEncoder().encode("Aa123456"))
//                .roles("ADMIN")
//                .authorities("biz1","biz2");
//
//
//        //jdbcAuthentication从数据库中获取，但是默认是以security提供的表结构
//        //usersByUsernameQuery 指定查询用户SQL
//        //authoritiesByUsernameQuery 指定查询权限SQL
//        //auth.jdbcAuthentication().dataSource(dataSource).usersByUsernameQuery(query).authoritiesByUsernameQuery(query);
//
//        //注入userDetailsService，需要实现userDetailsService接口
//        //auth.userDetailsService(userDetailsService);
//
//    }
//
//    @Bean
//    public PasswordEncoder passwordEncoder() {
//        return new BCryptPasswordEncoder();
//    }
//
//    @Override
//    public void configure(WebSecurity web) {
//        //将项目中静态资源路径开放出来
//        web.ignoring().antMatchers("/config/**", "/css/**", "/fonts/**", "/img/**", "/js/**");
//    }
//}
